#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@author: Lénia Andrade nº 5607
'''

import csv


class CreateCSV:
   
    '''
    This method creates a csv file referent to the first statistic (establishments per year) 
    '''
    def csv_establishments_year(self, year, establishments):
    
        file = open('../csv/Establishments_Year.csv', 'wb')

        fileWriter = csv.writer(file, delimiter=',')
        
        fileWriter.writerow(["Year", "Number of establishments"])
        fileWriter.writerow([year, len(establishments)])
        fileWriter.writerow([])
        fileWriter.writerow(["Establishments:"])
    
        for x in establishments:
            fileWriter.writerow([x.encode('utf-8')])
            pass

        file.close()
        pass
    
    
    
    '''
    This method creates a csv file referent to the second statistic
    (teachers divided per categories per establishment and per year)
    '''
    def csv_teachers_cat_estab_year(self, year, estab, cat, teachers):
            
        file = open('../csv/Teachers_Category_Establishment_Year.csv', 'wb')

        fileWriter = csv.writer(file, delimiter=',')
        
        fileWriter.writerow(["Year", "Establishment", "Category", "Number of Teachers"])
        fileWriter.writerow([year, estab.encode('utf-8'), cat.encode('utf-8'), len(teachers)])
        fileWriter.writerow([])
        fileWriter.writerow(["Teachers:"])
        
        for x in teachers:
            fileWriter.writerow([x.encode('utf-8')])
            pass

        file.close()
        pass
    
    
    
    '''
    This method creates a csv file referent to third statistic 
    (teachers divided per type of degree per establishment per category and per year)
    '''
    def csv_teachers_deg_estab_cat_year(self, year, estab, deg, cat, teachers):
            
        file = open('../csv/Teachers_Degree_Establishment_Category_Year.csv', 'wb')

        fileWriter = csv.writer(file, delimiter=',')
        
        fileWriter.writerow(["Year", "Establishment", "Degree", "Category", "Number of Teachers"])
        fileWriter.writerow([year, estab.encode('utf-8'), deg.encode('utf-8'), cat.encode('utf-8'), len(teachers)])
        fileWriter.writerow([])
        fileWriter.writerow(["Teachers:"])
        
        for x in teachers:
            fileWriter.writerow([x.encode('utf-8')])
            pass

        file.close()
        pass
        
    pass

        
        
